//
//  UIBarButton +Extension.swift
//  SinaWeibo
//
//  Created by 蒋琪 on 2017/5/24.
//  Copyright © 2017年 liuying. All rights reserved.
//

import UIKit

extension UIBarButtonItem{


    //传入:图片名称,target,action->快速创建对象
    //在分类中不能使用指定的构造器
    convenience init(normalImg:String,highlightedImg:String,target: Any?, action: Selector,title:String = ""){
    
        
        let btn = UIButton()
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        btn.setImage(UIImage(named:normalImg), for: .normal)
        btn.setImage(UIImage(named:highlightedImg), for: .highlighted)
        btn.sizeToFit()
        //添加点击事件
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        
        
        self.init()
        //给当前对象设置自定义视图
        self.customView = btn
        
    }
    
    
    
}
